home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-01-23 | 2.5 KB | 104 lines | [TEXT/KEEN] |
- #$ClipGlossary: a "magic clipboard" program that remembers and
- # expands glossary abbreviations.
- # To make an entry, Copy text of the form
- # gloss name entry
- # with nothing before "gloss", one or more spaces or tabs after,
- # the single-word name for the entry, one or more space or tabs,
- # and then the entry proper, which can occupy more than one line.
- # To expand a glossary name, type the name, select and Copy it,
- # and then Paste after the menu bar flashes.
- # Takes no input, remembers all entries to the file "Glossary".
-
- BEGIN {
- GlossaryFile = STDPATH "Glossary";
- LoadOldGlossary();
- clipCharsToWatch = 32;
- while (1) # run until <Command><period>...
- {
- # see if clipboard has changed
- if ((newClip = getclip(clipCharsToWatch)) != oldClip)
- {
- oldClip = newClip;
-
- if (substr(newClip, 1,5) == "gloss")
- {
- fullClip = getclip(); # gets calling editor's private clip
- MakeNewEntry();
- }
- else if (newClip in glossary)
- {
- fullClip = getclip(); # gets calling editor's private clip
- ExpandEntry();
- }
- }
- }
- }
-
- function LoadOldGlossary( name, entry)
- {
- while (getline x < GlossaryFile > 0)
- {
- if (x == "ENTRY")
- {
- entry = ""
- if (getline x < GlossaryFile > 0)
- {
- if (match(x, /^gloss[ \t]+/))
- {
- x = substr(x, RLENGTH+1);
- if (match(x, /^[^ \t]+/))
- {
- name = substr(x, 1, RLENGTH); # first word, the entry name
- match(x, /^[^ \t]+[ \t]+/); # after first word, the entry starts
- entry = substr(x, RLENGTH+1);
- while (getline x < GlossaryFile > 0)
- {
- if (x == "END")
- break;
- else
- entry = entry "\r" x;
- }
- glossary[name] = entry;
- }
- }
- }
- }
- }
- close(GlossaryFile);
- }
-
- function MakeNewEntry( name, entry)
- {
- if (match(fullClip, /^gloss[ \t]+/))
- {
- fullClip = substr(fullClip, RLENGTH+1);
- if (match(fullClip, /^[^ \t]+/)) # first word, the entry name
- {
- name = substr(fullClip, 1, RLENGTH);
- match(fullClip, /^[^ \t]+[ \t]+/); # after first word, the entry starts
- entry = substr(fullClip, RLENGTH+1);
- glossary[name] = entry;
- LogNewEntry();
- # flash menu bar to signal something happened
- beep(0);
- }
- }
- }
-
- function ExpandEntry( out)
- {
- out = glossary[fullClip];
- putclip(out);
- oldClip = substr(out, 1, 32); # this would happen anyway next time...
- # flash menu bar to signal something happened
- beep(0);
- }
-
- function LogNewEntry()
- {
- print "ENTRY" >> GlossaryFile;
- print "gloss " fullClip >> GlossaryFile;
- print "END" >> GlossaryFile;
- close (GlossaryFile);
- }
-